(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.AdminSecurityView = (function(_super) {

    __extends(AdminSecurityView, _super);

    function AdminSecurityView() {
      return AdminSecurityView.__super__.constructor.apply(this, arguments);
    }

    AdminSecurityView.prototype.el = $('#content');

    AdminSecurityView.prototype.initialize = function() {
      AdminSecurityView.__super__.initialize.apply(this, arguments);
      this.model.bind("change", this.render);
      return this.model.set("SuccessMessage", "FAIL");
    };

    AdminSecurityView.prototype.render = function() {
      var el, url, welcomeModel, welcomeView,
        _this = this;
      el = $(this.el);
      if (this.model.get("SuccessMessage") === "FAIL") {
        return this.GetTemplate(SiteMap.Admin.Security.LogOnTemplate, function(compiledTemplate) {
          el.html(compiledTemplate(_this.model.toJSON()));
          return Loading.Stop();
        });
      } else {
        Messages.WriteMessage(this.model.get("SuccessMessage"));
        url = this.model.get("ReturnUrl");
        if (url === null) {
          url = SiteMap.Admin.Content.Dashboard;
        }
        welcomeModel = new WelcomeModel();
        welcomeModel.set("isAuthorize", true);
        welcomeModel.set("Login", this.model.get("Login"));
        welcomeView = new WelcomeView({
          model: welcomeModel
        });
        welcomeView.render();
        if (!window.html5history) {
          return window.location.href = SiteMap.Admin.Content.Dashboard;
        } else {
          return this.Navigate(url, true);
        }
      }
    };

    AdminSecurityView.prototype.events = {
      "submit": "logOn"
    };

    AdminSecurityView.prototype.logOn = function(events) {
      var data,
        _this = this;
      events.preventDefault();
      Loading.Start();
      data = $(this.el).find("form").serialize();
      Messages.WriteMessage("Проверка имени пользователя и пароля...");
      return $.post(SiteMap.Admin.Security.LogOn, data, function(response) {
        Messages.WriteErrors(response.Errors);
        return _this.model.set({
          "Errors": response.Errors,
          "Login": response.Login,
          "ReturnUrl": response.ReturnUrl,
          "SuccessMessage": response.SuccessMessage
        });
      });
    };

    return AdminSecurityView;

  })(CustomView);

}).call(this);
